package com.fuxin.hanfu.controller;

import com.fuxin.hanfu.domain.Item;
import com.fuxin.hanfu.service.ItemService;
import com.fuxin.hanfu.uitls.MyResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/item")
public class ItemController {
    @Resource
    private ItemService itemService;
    //查询
    @GetMapping("/find")
    public List<Item> findList(Item item){
        return itemService.findList(item);
    }
     //推荐查询
    @GetMapping("/findRecommend")
    public List<Item> findRecommend(Item item){
        return itemService.findRecommend(item);
    }

    /*根据id查询*/
    @GetMapping("/find/{id}")
    public MyResponse findById(@PathVariable Integer id) {
        return MyResponse.toJson(true, itemService.findById(id));
    }

    /*新增*/
    @PostMapping("/add")
    public Integer insert(@RequestBody Item item) {
        return itemService.insert(item);
    }

    /*修改*/
    @PutMapping("/update")
    public MyResponse update(@RequestBody Item item) {
        return MyResponse.toJson(true, itemService.update(item));
    }

    /*删除*/
    @DeleteMapping("/delete/{id}")
    public Integer delete(@PathVariable Integer id) {
        return  itemService.delete(id);
    }

}
